/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.zx.course.exercises.user.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.zx.course.exercises.user.entity.TcourseExercisesUser;
import com.jeesite.modules.zx.course.exercises.user.service.TcourseExercisesUserService;

/**
 * 课程练习记录表Controller
 * @author zpp
 * @version 2020-02-17
 */
@Controller
@RequestMapping(value = "${adminPath}/zx/course/exercises/user/tcourseExercisesUser")
public class TcourseExercisesUserController extends BaseController {

	@Autowired
	private TcourseExercisesUserService tcourseExercisesUserService;
	
	/**
	 * 获取数据
	 */
	@ModelAttribute
	public TcourseExercisesUser get(String id, boolean isNewRecord) {
		return tcourseExercisesUserService.get(id, isNewRecord);
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:view")
	@RequestMapping(value = {"list", ""})
	public String list(TcourseExercisesUser tcourseExercisesUser, Model model) {
		model.addAttribute("tcourseExercisesUser", tcourseExercisesUser);
		return "modules/zx/course/exercises/user/tcourseExercisesUserList";
	}
	
	/**
	 * 查询列表数据
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:view")
	@RequestMapping(value = "listData")
	@ResponseBody
	public Page<TcourseExercisesUser> listData(TcourseExercisesUser tcourseExercisesUser, HttpServletRequest request, HttpServletResponse response) {
		tcourseExercisesUser.setPage(new Page<>(request, response));
		Page<TcourseExercisesUser> page = tcourseExercisesUserService.findPage(tcourseExercisesUser);
		return page;
	}

	/**
	 * 查看编辑表单
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:view")
	@RequestMapping(value = "form")
	public String form(TcourseExercisesUser tcourseExercisesUser, Model model) {
		model.addAttribute("tcourseExercisesUser", tcourseExercisesUser);
		return "modules/zx/course/exercises/user/tcourseExercisesUserForm";
	}

	/**
	 * 保存课程练习记录表
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated TcourseExercisesUser tcourseExercisesUser) {
		tcourseExercisesUserService.save(tcourseExercisesUser);
		return renderResult(Global.TRUE, text("保存课程练习记录表成功！"));
	}
	
	/**
	 * 停用课程练习记录表
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:edit")
	@RequestMapping(value = "disable")
	@ResponseBody
	public String disable(TcourseExercisesUser tcourseExercisesUser) {
		tcourseExercisesUser.setStatus(TcourseExercisesUser.STATUS_DISABLE);
		tcourseExercisesUserService.updateStatus(tcourseExercisesUser);
		return renderResult(Global.TRUE, text("停用课程练习记录表成功"));
	}
	
	/**
	 * 启用课程练习记录表
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:edit")
	@RequestMapping(value = "enable")
	@ResponseBody
	public String enable(TcourseExercisesUser tcourseExercisesUser) {
		tcourseExercisesUser.setStatus(TcourseExercisesUser.STATUS_NORMAL);
		tcourseExercisesUserService.updateStatus(tcourseExercisesUser);
		return renderResult(Global.TRUE, text("启用课程练习记录表成功"));
	}
	
	/**
	 * 删除课程练习记录表
	 */
	@RequiresPermissions("zx:course:exercises:user:tcourseExercisesUser:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(TcourseExercisesUser tcourseExercisesUser) {
		tcourseExercisesUserService.delete(tcourseExercisesUser);
		return renderResult(Global.TRUE, text("删除课程练习记录表成功！"));
	}
	
}